
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

public class Demo6 {
    public static void main(String[] args) throws IOException {
//        InputStream inputStream = null;
//        try {
//            inputStream = new FileInputStream("d:/test.txt");
//
//            while (true) {
////            int b = inputStream.read();
////            if (b == -1) {
////                // 读取完毕
////                break;
////            }
////            System.out.printf("0x%X ", b);
//
//                byte[] bytes = new byte[1024];
//                int n = inputStream.read(bytes);
//                System.out.println("n = " + n);
//                if (n == -1) {
//                    // 读取完毕, n 就是 -1 .
//                    break;
//                }
//                for (int i = 0; i < n; i++) {
//                    System.out.printf("0x%x ", bytes[i]);
//                }
//                System.out.println();
//            }
//        } finally {
//            inputStream.close();
//        }

        try (InputStream inputStream = new FileInputStream("d:/test.txt")) {
            byte[] bytes = new byte[1024];
            int n = inputStream.read(bytes);
            for (int i = 0; i < n; i++) {
                System.out.printf("0x%x ", bytes[n]);
            }
        }
    }
}